<?php

global $objApi;
global $objUser;

$objApi->register(new Route(Api::POST, "/api/user/login", function($api, $self){
	global $objUser;
	global $objSession;

	if($objUser->login(Utils::cleanArg($_POST["username"]), Utils::cleanArg($_POST["password"]))){
		$api->send($objSession["user"]);
	} else {
		$api->send(array("msg" => "User data invalid!"), 401);
	}
}));

$objApi->register(new Route(Api::GET, "/api/user/logout", function($api, $self){
	global $objUser;
	$objUser->logout();
}));

$objApi->register(new Route(Api::GET, "/api/user/status", function($api, $self){
	global $objUser;
	global $objSession;

	if($objUser->blnLoggedIn == true){
		$api->send($objSession["user"]);
	} else {
		$api->send(array("msg" => "Not logged in!"), 401);
	}
}));
?>